package com.example.hello.client.NavSearch;

import com.example.hello.BootstrapNavSearch;
import com.github.gwtbootstrap.client.ui.constants.Alignment;
import com.github.gwtbootstrap.client.ui.constants.FormType;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.communication.StateChangeEvent;
import com.vaadin.client.ui.AbstractComponentConnector;
import com.vaadin.shared.ui.Connect;

@Connect(BootstrapNavSearch.class)
public class BootstrapNavSearchConnector extends AbstractComponentConnector {

    @Override
    protected Widget createWidget() {
        return GWT.create(VBootstrapNavSearch.class);
    }

    @Override
    public BootstrapNavSearchState getState() {
        return (BootstrapNavSearchState) super.getState();
    }

    @Override
    public VBootstrapNavSearch getWidget() {
        return (VBootstrapNavSearch) super.getWidget();
    }

    @Override
    public void onStateChanged(StateChangeEvent stateChangeEvent) {
        super.onStateChanged(stateChangeEvent);

        BootstrapNavSearchState state = getState();

        VBootstrapNavSearch navSearch = getWidget();

        navSearch.setPlaceholder(state.getPlaceholder());
        navSearch.setAlignment(Alignment.valueOf(state.getAlignment()));
        navSearch.setType(FormType.valueOf(state.getType()));
        navSearch.setSize(state.getSize());
    }

}